package com.example.staggeredgridviewdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

import com.origamilabs.library.views.StaggeredGridView;

/**
 * 
 * This will not work so great since the heights of the imageViews 
 * are calculated on the iamgeLoader callback ruining the offsets. To fix this try to get 
 * the (intrinsic) image width and height and set the views height manually. I will
 * look into a fix once I find extra time.
 * 
 * @author Maurycy Wojtowicz
 *
 */
public class MainActivity extends Activity {

	/**
	 * Images are taken by Romain Guy ! He's a great photographer as well as a
	 * great programmer. http://www.flickr.com/photos/romainguy
	 */
	
	private String urls[] = { 
			"http://192.168.1.100/imgs/1.jpg",
			"http://192.168.1.100/imgs/2.png",
			"http://192.168.1.100/imgs/3.png",
			"http://192.168.1.100/imgs/4.png",
			"http://192.168.1.100/imgs/5.png",
			"http://192.168.1.100/imgs/6.png",
			"http://192.168.1.100/imgs/7.jpg",
			"http://192.168.1.100/imgs/8.jpg",
			"http://192.168.1.100/imgs/9.jpg",
			"http://192.168.1.100/imgs/10.jpg",

	};
	/**
	 * This will not work so great since the heights of the imageViews 
	 * are calculated on the iamgeLoader callback ruining the offsets. To fix this try to get 
	 * the (intrinsic) image width and height and set the views height manually. I will
	 * look into a fix once I find extra time.
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		StaggeredGridView gridView = (StaggeredGridView) this.findViewById(R.id.staggeredGridView1);
		
		int margin = getResources().getDimensionPixelSize(R.dimen.margin);
		
		gridView.setItemMargin(margin); // set the GridView margin
		
		gridView.setPadding(margin, 0, margin, 0); // have the margin on the sides as well 
		
		StaggeredAdapter adapter = new StaggeredAdapter(MainActivity.this, R.id.imageView1, urls);
		
		gridView.setAdapter(adapter);
		adapter.notifyDataSetChanged();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
}
